package com.probox.modules.controller.product;

import com.probox.common.core.web.controller.BaseController;
import com.probox.common.core.web.domain.AjaxResult;
import com.probox.common.core.web.page.TableDataInfo;
import com.probox.common.log.annotation.Log;
import com.probox.common.log.enums.BusinessType;
import com.probox.common.security.annotation.PreAuthorize;
import com.probox.common.entity.domain.product.ProductComment;
import com.probox.common.entity.domain.product.vo.ProductCommentQuery;
import com.probox.common.entity.domain.product.vo.ProductCommentVo;
import com.probox.common.entity.service.product.IProductCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品评论信息Controller
 *
 *
 * @date 2021-06-07
 */
@RestController
@RequestMapping("/product/comment")
public class ProductCommentController extends BaseController {
    @Autowired
    private IProductCommentService productCommentService;

    /**
     * 查询商品评论信息列表
     */
    @PreAuthorize(hasPermi = "product:comment:list")
    @GetMapping("/list")
    public TableDataInfo list(ProductCommentQuery productCommentQuery) {
        startPage();
        List<ProductCommentVo> list = productCommentService.queryList(productCommentQuery);
        return getDataTable(list);
    }


    /**
     * 获取商品评论信息详细信息
     */
    @PreAuthorize(hasPermi = "product:comment:query")
    @GetMapping(value = "/{commentUid}")
    public AjaxResult getInfo(@PathVariable("commentUid") Long commentUid) {
        return AjaxResult.success(productCommentService.selectProductCommentById(commentUid));
    }


    /**
     * 修改商品评论信息
     */
    @PreAuthorize(hasPermi = "product:comment:edit")
    @Log(title = "商品评论信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductComment productComment) {
        return toAjax(productCommentService.updateProductComment(productComment));
    }

    @PreAuthorize(hasPermi = "product:comment:edit")
    @Log(title = "商品评论信息", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult editS(@RequestBody ProductComment productComment) {
        return toAjax(productCommentService.updateComment(productComment));
    }


    /**
     * 删除商品评论信息
     */
    @PreAuthorize(hasPermi = "product:comment:remove")
    @Log(title = "商品评论信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{commentUids}")
    public AjaxResult remove(@PathVariable Long[] commentUids) {
        return toAjax(productCommentService.deleteProductCommentByIds(commentUids));
    }
}
